package com.huidu.bitrade.service;

import com.huidu.bitrade.entity.AcMember;
import com.huidu.bitrade.entity.Member;
import com.huidu.bitrade.entity.MemberWallet;
import com.huidu.bitrade.entity.OtcCoin;
import com.huidu.bitrade.entity.transform.AuthMember;
import com.huidu.bitrade.enums.MemberStarEnum;
import com.huidu.bitrade.exception.ServiceException;
import com.huidu.bitrade.service.impl.HdzPurchasePayServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.math.BigDecimal;
import java.util.Objects;

public interface PurchaseService {

    /**
     * 支付处理
     * @param authMember 当前登录用户
     * @param starEnum 星级枚举
     * @param payType 1、币本位+金本位购买 2、金本位购买
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    default boolean purchaseFunction(AuthMember authMember, MemberStarEnum starEnum ,Integer purchaseCount, Integer payType,BigDecimal currentHdz) throws ServiceException {
        Member oldMember = getMember(authMember.getId());
        purchaseHandle(authMember, starEnum,purchaseCount, payType,currentHdz);
        updateMember(oldMember, starEnum);
        upgradeStar(authMember.getId(),oldMember.getMemberStar());
        return true;
    }

    /**
     * 导入hdz时，给用户添加星级，仅用于导入使用
     * @param authMember
     * @param starEnum
     * @param purchaseCount
     * @param payType
     * @param currentHdz
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    default boolean purchaseFunctionImport(AuthMember authMember, MemberStarEnum starEnum ,Integer purchaseCount, Integer payType,BigDecimal currentHdz) throws ServiceException {
        Member oldMember = getMember(authMember.getId());
        purchaseHandleImport(authMember, starEnum,purchaseCount, payType,currentHdz);
        updateMember(oldMember, starEnum);
        upgradeStar(authMember.getId(),oldMember.getMemberStar());
        return true;
    }

    boolean purchaseHandle(AuthMember authMember, MemberStarEnum starEnum, Integer purchaseCount , Integer payType, BigDecimal currentHdz);
    boolean purchaseHandleImport(AuthMember authMember, MemberStarEnum starEnum, Integer purchaseCount, Integer payType, BigDecimal currentHdz);

    Member getMember(Long id);

    /**
     * 修改用户信息
     * @param member
     * @param starEnum 星级枚举
     */
    void updateMember(Member member, MemberStarEnum starEnum) throws ServiceException;

    /**
     * 发放奖励
     */
//    void distribute();

    /**
     * 用户升星，奖励推荐人
     * @param uid 用户id
     */
    void upgradeStar(Long uid,Integer oldStar);
}
